//雷俊峰
function loadSelect(dom,data,value,name){
	var result="<option value=''>请选择</option>";
	if(data!=null || data!=""){
		$.each(data,function(index,content){
			result +="<option value="+content[value]+">"+content[name]+"</option>";
		})
	}
	$(dom).html(result);
}
function refreshTable(tableid,formid){	 
	 var params =$(formid).serializeObject();		 
	if(params.zjlx==0){
		params.zjlx="";
	}
	if(params.xb==0){
		params.xb=="";
	}
	if(params.mz==0){
		params.mz="";
	}
	 params["pageNumber"] = 1;
	 params["limit"] = pageSize;
	 params["offset"] = 0;	 
	 $(tableid).bootstrapTable('refresh',{query:params});	
};
function refreshScTable(tableid,formid){	 
	 var params =$(formid).serializeObject();		 
	if(params.audioEF==0){
		params.audioEF="";
	}
	if(params.videoEF==0){
		params.videoEF=="";
	}
	if(params.rightsType==0){
		params.rightsType="";
	}
	 params["pageNumber"] = 1;
	 params["limit"] = pageSize;
	 params["offset"] = 0;	 
	 $(tableid).bootstrapTable('refresh',{query:params});	
};
$.fn.serializeObject = function(){
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name] !== undefined) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value.trim() || '');
		} else {
			o[this.name] = this.value.trim() || '';
		} 
	});

    var $radio = $('input[type=radio],input[type=checkbox]',this);
    $.each($radio,function(){
    	if(this.checked){    	
    		if(!o.hasOwnProperty(this.name)){
    			o[this.name] = this.value.trim() || '';
    		}
    	}
    });
	return o;
};
function loadData(formID,jsonStr){
	var obj =jsonStr;
	var key,value,tagName,type,arr;
	for(x in obj){
		key = x;
		value = obj[x];		
		//$(formID+" [name='"+key+"'],"+formID+" [name='"+key+"[]']").each(function(){
		$(formID+" [name='"+key+"'],"+formID+" [name='"+key+"[]']").each(function(){
			tagName = $(this)[0].tagName;
			type = $(this).attr('type');
			if(tagName=='INPUT'){
				if(type=='radio'){
					$(this).prop('checked',$(this).val()==value);
				}else if(type=='checkbox'){
					if((value+"").indexOf(',')>-1){
						arr = value.split(',');
					}else{
						arr = value;
					}
					for(var i =0;i<arr.length;i++){
						if($(this).val()==arr[i]){
							$(this).prop('checked',true);
							break;
						}
					}
				}else{
					$(this).val(value);
				}
			}else if(tagName=='SELECT' || tagName=='TEXTAREA'){
				$(this).val(value);
			}else if(tagName=='LABEL'){
				$(this).text(value);
			}else{
				$(this).val(value);
			}			
		});
	}
}

function checkform(formid){
	var isCheck= true;
	//验证必输项
	$(formid+" [required='true']").each(function(){
		if($(this).val()==null || $(this).val().trim()==""){
			errorMsg = $(this).attr("errorMsg")==undefined?"该项为必填项":$(this).attr("errorMsg");			
			//$(this).attr("placeholder",errorMsg);
			$(this).next("span").remove();
			$(this).after("<span class='apendhtml' style='color: red;margin-left: 5px;'>"+errorMsg+"</span>");
			isCheck = false;
		}else if($(this).attr("type")=="number"){
			var value = parseInt($(this).val());
			if(value<1){
				errorMsg = $(this).attr("errorMsg")==undefined?"数字须大于0":$(this).attr("errorMsg");			
				//$(this).attr("placeholder",errorMsg);
				$(this).next("span").remove();
				$(this).after("<span class='apendhtml' style='color: red;margin-left: 5px;'>"+errorMsg+"</span>");
				isCheck = false;
			}else{
				$(this).next("span").remove();
			}
		}else{
			$(this).next("span").remove();
		}
	})
	return isCheck;
}


//验证手机号
function checkphone(ele) { 
	var lxrsjh =$(ele).val();
	if(lxrsjh=="" || lxrsjh == null){
		$(ele).next("span").remove();
		$(ele).after("<span class='apendhtml' style='color: red;margin-left: 5px;'>该项为必填项</span>");
		return false;
	}
	//是否符合规则	
  //var ret = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
	var ret = /^(13|14|15|16|17|18|19)\d{9}$/;
  if(!ret.test(lxrsjh)){
		$(ele).next("span").remove();
		$(ele).after("<span class='apendhtml' style='color: red;margin-left: 5px;'>手机号不符合规则</span>");
    return false;
  }	
  $(ele).next("span").remove();
	return true;
}
function queryTableNoPage(tableid, url, columns,queryParams) {	
	$(tableid).bootstrapTable({
		url: url,
        queryParamsType: '',              //默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
        queryParams:queryParams,
        method: "get",
        pagination: false,
        sidePagination: "server",         //分页方式：client客户端分页，server服务端分页（*）
        striped: true,                    //是否显示行间隔色
        cache: false,
        columns:columns
	});
}	
//校验邮箱
function checkemail(ele){	
	var lxryx =$(ele).val();
	if(lxryx=="" || lxryx == null){
		$(ele).next("span").remove();
		$(ele).after("<span class='apendhtml' style='color: red;margin-left: 5px;'>该项为必填项</span>");
		return false;
	}
	if(lxryx.length>30){
		$(ele).next("span").remove();
		$(ele).after("<span class='apendhtml' style='color: red;margin-left: 5px;'>字符数不能超过30</span>");
		return false;
	}
	//是否符合规则	
  var ret = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  if(!ret.test(lxryx)){
		$(ele).next("span").remove();
		$(ele).after("<span class='apendhtml' style='color: red;margin-left: 5px;'>邮箱不符合规则</span>");
    return false;
  }	    
  $(ele).next("span").remove();
	return true;
}
function alertFunc(notice,callbackCode){
	if(notice!=null)
		window.top.bootbox.alert(notice,callbackCode);
	else
		window.top.bootbox.alert('null',callbackCode);
}
function ajaxFunc(t_type,t_async,t_url,t_data,t_func,t_dom,document){
	var l ;
	if(typeof(document)!="undefined"){
	l = Ladda.create(document); //对此按钮创建Ladda对象（防止多次点击对象）
    l.start();//（开始时发送请求按钮加载中）
	}
	$.ajax({
        type:t_type,
        dataType: 'json',
        async:t_async,
        url:t_url,
        data:t_data,
        success:function(data){
            t_func(data,t_dom);
        }
    });
	if(typeof(document)!="undefined"){ 
		l.stop();
		}
}